package com.yyh.io2;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/*字节数组流【内存流】*/
public class Test1 {
    public static void main(String[] args) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        //向内存中写入数据
        bos.write("hello".getBytes());
        bos.write("world".getBytes());
        //创建流管道
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        //String str= " ";
        //打开水龙头，开始读
        /*int bit;
        while ((bit = bis.read()) != -1) {
            str += (char) bit;
        }
        System.out.println(str);*/
        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, len));
        }


        //关闭水龙头
        bis.close();
        bos.close();
    }
}
